//
//  AuthorizationController.m
//  NtoccDriverNew
//
//  Created by 张天兴 on 2024/11/18.
//  Copyright © 2024 GCY. All rights reserved.
//

#import "AuthorizationController.h"
#import "CYWebViewViewController.h"

@interface AuthorizationController ()
@property (nonatomic, strong) NSString *htmlUrlStr;

@end

@implementation AuthorizationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"用户信息授权";
    // Do any additional setup after loading the view from its nib.
    _aggressiveButton.titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
    NSString *agreementStr = [NSString stringWithFormat:@"《云南省货物运输业小规模纳税人委托网络平台道路货物运输企业代申报缴纳税费、代办理临时税务登记、代办理税务注销手续协议书》"];
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:[@"同意" stringByAppendingString:agreementStr]];
    [attString addAttribute:(NSString*)NSForegroundColorAttributeName value:Light_TextColor range:[_aggressiveButton.titleLabel.text rangeOfString:@"同意"]];
    [attString addAttribute:(NSString*)NSForegroundColorAttributeName value:Theme_ColorValue range:[@"同意《云南省货物运输业小规模纳税人委托网络平台道路货物运输企业代申报缴纳税费、代办理临时税务登记、代办理税务注销手续协议书》" rangeOfString:agreementStr]];
    [_aggressiveButton setAttributedTitle:attString forState:UIControlStateNormal];
    _comitiButton.layer.masksToBounds = YES;
    _comitiButton.layer.cornerRadius = 10;
    [_aggressiveButton addTarget:self action:@selector(aggressiveButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
    NSString * codeStr = [UserDefaultUtil valueForKey:userDriverCode];
    NSString *urlString = CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], @"/dyt/elecSign/createContract");
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:codeStr forKey:@"driverCodes"];
[HTTPManager postNetworkRequest: urlString withParameter:dict withVC:self netName:self.navigationItem.title success:^(id response, NSString *msg) {
    self.htmlUrlStr = CJStringWithFormat(@"%@",response[@"html"]);
} failure:^(NSInteger code, NSString *msg) {
    
}];

}
- (IBAction)comitButtonAction:(UIButton *)sender {
    if (!self.isSelectedButton.isSelected) {
        NSString *agreementStr = [NSString stringWithFormat:@"请先认真阅读协议,并同意协议"];
        [XSInfoView showInfo:agreementStr onView:self.view];
        return;
    }
    NSString * codeStr = [UserDefaultUtil valueForKey:USER_CODE];
    NSString *urlString = CJStringWithFormat(@"%@/dyt/elecSign/%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl],codeStr);
    [HTTPManager getNetworkRequest:urlString withParameter:@{} withVC:self netName:@"盖章" success:^(id response, NSString *msg) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
            [self.navigationController popViewControllerAnimated:YES];
        });
        } failure:^(NSInteger code, NSString *msg) {
            
        }];
    
}
- (void)aggressiveButtonAction{
    CYWebViewViewController *webVC = [[CYWebViewViewController alloc] init];
    webVC.titleString = @"税务发票代办委托书";
    webVC.urlString = self.htmlUrlStr;
    webVC.state = 4;
    [self.navigationController pushViewController:webVC animated:YES];
}
- (IBAction)isSelectedButton:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected == YES) {
        CYWebViewViewController *webVC = [[CYWebViewViewController alloc] init];
        webVC.titleString = @"税务发票代办委托书";
        webVC.urlString = self.htmlUrlStr;
        webVC.state = 4;
        [self.navigationController pushViewController:webVC animated:YES];

    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
